
#ifndef __COM_H__
#define __COM_H__
 
typedef  unsigned short UINT16;
typedef  unsigned char  UINT8;

#ifndef MIN
#define MIN(a,b)  (((a)<(b))?(a):(b))
#endif 

#define WORDSWAP(w)		(((w) >> 8) | \
						(((w) << 8) & 0xFF00))

#define DWORDSWAP(dw)	(((dw) >> 24) | \
						(((dw) >> 8) & 0x0000FF00) | \
						(((dw) << 8) & 0x00FF0000) | \
						(((dw) << 24) & 0xFF000000))



unsigned long atox(const char *str);
void xtoa(char * str , BYTE dx);

class CCom
{
public:
    CCom();
    virtual ~CCom();
public:
    BOOL OpenSerialPort(int PortNum, int Baud);
    void CloseSerialPort();

    BOOL SetBaudRate(int nNewRate);
    INT  GetBaudRate(void);

    UINT32  SendData(void *pData, int nDataLen = -1);
    UINT32  ReceiveData(void *pDataBuf, UINT32 nBufLen);
    UINT32  ReceiveDataEx(void *pDataBuf, UINT32 nBufLen);

    VOID    ClearSerialBuff();
    UINT32  TxBufDataTotal();
    UINT32  RxBufDataTotal();

    HANDLE GetPortHandle();
    BOOL   PortOpenStatus();

private:
    HANDLE	m_hCOM ;
    int     m_nComNum;
    int     m_nBaud;
};

//DWORD PackedData(BYTE * pdata, DWORD dwLen);
#endif